﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GeneratorSelections.DataDictionary;
using GeneratorSelections.Repository;

namespace GeneratorSelections
{
    public partial class TableSelectionForm : Form
    {
        public TableSelectionForm()
        {
            InitializeComponent();
        }

        public Table SelectedTable { get; set; }
        private List<string> _tableNames= new List<string>();

        public void Init(string tableNameLike)
        {
            _tableNames = new TableRepository().GetTableNames(tableNameLike);
            selectedTableBindingSource.DataSource = _tableNames;
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            DialogResult= DialogResult.OK;
            var tableName = tableNamesListBox.SelectedItem.ToString();
            SelectedTable= new Table(tableName)
                {
                    ColumnList = new ColumnRepository().GetColumns(tableName)
                };
        }
    }
}
